import { lib, game, ui, get, ai, _status } from '../../../noname.js';
import { swTool } from "../main/swTool.js";

//身份场
swTool.comboObject(lib.mode.identity.connect, {
    connect_identity_mode: {
        item: {
/*            kangjin: '<span style="color:red;">抗金</span>',*/
			freeChoiceSkill: '<span class="sw_control">自选技能</span>',
			freeChoiceIdentity: '<span class="sw_control">自选身份</span>',
            //"4v4": '<span style="color:red;">四反三忠一主</span>',
            //neimin: '<span style="color:red;">内替换为民（前提是有民）</span>',
            // 'whlw':'<span style="color:red;">文和乱武</span>',
            //'clone': '<span style="color:red;">全选一样</span>',
            //'skill': '<span style="color:red;">随机技能</span>',
            // 'tafang':'<span style="color:skyblue;">塔防</span>',
        },
		name: '<span class="sw_control">游戏模式</span>',
	},
	connect_identity_freeChoiceSkillNum: {
		name: '<span class="sw_control">技能选择数</span>',
		frequent: true,
		init: '2',
		item: {
			"1": '1',
			"2": '2',
			"3": '3',
			"4": '4',
			"5": '5',
			"6": '6',
			"7": '7',
			"8": '8',
		},
		intro: '选将的时候每个人选多少个技能<br>务必计算好将池数量是足够的！'
	},
	connect_identity_zhuSkillHidePercent: {
		name: '<span class="sw_control">主公技能隐藏个数</span>',
		frequent: true,
		init: '0',
		item: Array.from({ length: 9 }, (_, i) => String(i)),
		intro: '游戏开始前主公技能隐藏的个数<br>在游戏开始前主公的后X个技能其他人不可见（X为此项配置值）'
	},
	connect_identity_randomSexAndGroup: {
		name: '<span class="sw_control">随机性别与势力</span>',
		init: false,
		frequent: true,
		intro: '仅自选技能模式，跳过选择势力的部分，改为随机性别和势力'
	},
	connect_identity_hideNickname: {
		name: '<span class="sw_control">选身份时隐藏昵称</span>',
		init: false,
		frequent: true,
		intro: '仅自选身份模式，在选择身份的过程中，所有玩家的昵称将被隐藏。'
	},
	connect_identity_banSkill:{
		name: '<span class="sw_control" style="text-decoration: underline">添加单独禁用技能</span>',
		clear:true,
		frequent:true,
		onclick:function(){
			const that = this;
			let str = "";
			if(lib?.config?.mode_config?.identity?.connect_identity_banSkill) str = lib.config.mode_config.identity.connect_identity_banSkill.join(' ')
			game.prompt(`###请输入要禁用的技能名字或者技能ID，多个技能用空格分割###${ str }`,function(str){
				if(str === false) return;
				var skills = [];
				if(str) skills = str.split(" ")
				game.saveConfig("connect_identity_banSkill", skills, that?.parentElement?.parentElement?.parentElement?.querySelector(".active")?.mode);
			});
			///document.querySelector('textarea').value = "aaa"
		},
	},
    connect_identity_listNum: {
		name: '<span class="sw_control">玩家选将框</span>',
        frequent: true,
        init: 'normal',
        item: {
            "normal": '正常',
            "10": '十个',
            "20": '二十个',
            "30": '三十个',
            "40": '四十个',
            "50": '五十个',
            "60": '六十个',
            "70": '七十个',
            "80": '八十个',
            "90": '九十个',
            "100": '一百个',
            'dianjiang': '自由点将'
        },
        restart: true,
        intro: '选将的时候每个人多少个选将框<br>自选技能模式下为每人技能框数量<br>务必计算好将池数量是足够的！<br>自由点将在自选技能模式不生效！'
    },
    connect_chooseCharacter_moreTime: {
		name: '<span class="sw_control">选将时间</span>',
        frequent: true,
        item: {
            '10': '10秒',
            '15': '15秒',
            '30': '30秒',
            '60': '60秒',
            '90': '90秒',
            '120': '120秒',
        },
		init: lib.configOL.choose_timeout || '30',
		intro: "选将的时候的时间限制<br>自选技能模式下为选技能的时间限制"
    },
    connect_identity_neiReplaceZhong: {
		name: '<span class="sw_control">内奸替换为忠臣</span>',
		intro: '内奸替换为忠臣',
        init: false,
        frequent: true,
    },
	// connect_choose_timeout: {
	// 	name: '<span class="sw_control">出牌时限</span>',
	// 	init: "30",
	// 	item: {
	// 		10: "10秒",
	// 		15: "15秒",
	// 		20: "20秒",
	// 		25: "25秒",
	// 		30: "30秒",
	// 		40: "40秒",
	// 		50: "50秒",
	// 		60: "60秒",
	// 		90: "90秒",
	// 	},
	// 	connect: true,
	// 	frequent: true,
	// },
})
lib.mode.identity.connect.update = function (config, map) {
	if (config.connect_identity_mode == "stratagem") {
		map.connect_round_one_use_fury.show();
	} else {
		map.connect_round_one_use_fury.hide();
	}

	const switchMode = {
		freeChoiceIdentity() {
			const show = [
				'connect_enable_year_limit',
				'connect_double_character',
				'connect_player_number',
				'connect_choice_zhu',
				'connect_limit_zhu',
				'connect_enhance_zhu',
				'connect_choice_zhong',
				'connect_choice_fan',
				'connect_choice_nei',
				'connect_double_nei',
				'connect_identity_listNum',
				'connect_identity_hideNickname',
			]
			const hide = [
				'connect_enable_commoner',
				'connect_choice_commoner',
				'connect_zhong_card',
				'connect_identity_freeChoiceSkillNum',
				'connect_identity_zhuSkillHidePercent',
				'connect_identity_randomSexAndGroup',
				'connect_identity_banSkill',
				'connect_special_identity',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		freeChoiceSkill() {
			const show = [
				'connect_identity_zhuSkillHidePercent',
				'connect_identity_randomSexAndGroup',
				'connect_identity_banSkill',
				'connect_identity_freeChoiceSkillNum',
				'connect_identity_listNum',
				'connect_enable_commoner',
				'connect_limit_zhu',
				'connect_enhance_zhu',
				'connect_double_nei',
				'connect_enable_year_limit',
				'connect_player_number',
			]
			const hide = [
				'connect_zhong_card',
				'connect_double_character',
				'connect_choice_zhu',
				'connect_choice_zhong',
				'connect_choice_fan',
				'connect_choice_nei',
				'connect_choice_commoner',
				'connect_special_identity',
				'connect_identity_hideNickname',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		zhong() {
			const show = [
				'connect_identity_listNum',
				'connect_enable_year_limit',
				'connect_zhong_card',
				'connect_double_character',
			]
			const hide = [
				'connect_identity_zhuSkillHidePercent',
				'connect_identity_randomSexAndGroup',
				'connect_identity_hideNickname',
				'connect_identity_banSkill',
				'connect_identity_freeChoiceSkillNum',
				'connect_player_number',
				'connect_choice_zhu',
				'connect_limit_zhu',
				'connect_enhance_zhu',
				'connect_choice_zhong',
				'connect_choice_fan',
				'connect_choice_nei',
				'connect_double_nei',
				'connect_enable_commoner',
				'connect_choice_commoner',
				'connect_special_identity',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		stratagem() {
			const show = [
				'connect_identity_listNum',
				'connect_double_character',
				'connect_player_number',
				'connect_choice_zhu',
				'connect_choice_zhong',
				'connect_choice_fan',
				'connect_choice_nei',
				'connect_enable_year_limit'
			]
			const hide = [
				'connect_identity_zhuSkillHidePercent',
				'connect_identity_randomSexAndGroup',
				'connect_identity_hideNickname',
				'connect_identity_banSkill',
				'connect_identity_freeChoiceSkillNum',
				'connect_limit_zhu',
				'connect_enhance_zhu',
				'connect_double_nei',
				'connect_enable_commoner',
				'connect_choice_commoner',
				'connect_zhong_card',
				'connect_special_identity',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		purple() {
			const show = [
				'connect_identity_listNum',
			]
			const hide = [
				'connect_identity_zhuSkillHidePercent',
				'connect_identity_randomSexAndGroup',
				'connect_identity_hideNickname',
				'connect_identity_banSkill',
				'connect_identity_freeChoiceSkillNum',
				'connect_player_number',
				'connect_choice_zhu',
				'connect_limit_zhu',
				'connect_enhance_zhu',
				'connect_choice_zhong',
				'connect_choice_fan',
				'connect_choice_nei',
				'connect_double_nei',
				'connect_enable_commoner',
				'connect_choice_commoner',
				'connect_enable_year_limit',
				'connect_zhong_card',
				'connect_special_identity',
				'connect_double_character',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		default() {
			const hide = [
				'connect_identity_freeChoiceSkillNum',
				'connect_zhong_card',
				'connect_identity_zhuSkillHidePercent',
				'connect_identity_randomSexAndGroup',
				'connect_identity_hideNickname',
				'connect_identity_banSkill',
			]
			const show = [
				'connect_enable_year_limit', 
				'connect_choice_nei',
				'connect_choice_fan',
				'connect_choice_zhong',
				'connect_enhance_zhu',
				'connect_limit_zhu',
				'connect_choice_zhu',
				'connect_player_number',
				'connect_double_character',

				'connect_identity_listNum',
				'connect_chooseCharacter_moreTime',
				'connect_identity_neiReplaceZhong',
			]
			hide.forEach(i => map[i] && map[i].hide())
			show.forEach(i => map[i] && map[i].show())
			map.connect_double_nei[config.connect_player_number != "2" && !config.connect_enable_commoner ? "show" : "hide"]();
			map.connect_enable_commoner[config.connect_player_number != "2" && !config.connect_double_nei ? "show" : "hide"]();
			map.connect_choice_commoner[config.connect_enable_commoner ? "show" : "hide"]();

			if (config.connect_player_number == "8") {
				map.connect_special_identity.show();
			} else {
				map.connect_special_identity.hide();
			}
		}
	}
	switchMode[config.connect_identity_mode in switchMode ? config.connect_identity_mode : 'default']()
}
//对决
swTool.comboObject(lib.mode.versus.connect, {
	connect_versus_listNum: {
		name: '<span class="sw_control">玩家选将框</span>',
		frequent: true,
		init: 'normal',
		item: {
			"normal": '正常',
			"10": '十个',
			"20": '二十个',
			"30": '三十个',
			"40": '四十个',
			"50": '五十个',
			"60": '六十个',
			"70": '七十个',
			"80": '八十个',
			"90": '九十个',
			"100": '一百个',
			//'dianjiang': '自由点将'
		},
		restart: true,
		intro: '选将的时候每个人多少个选将框<br>务必计算好将池数量是足够的！'
	},
})

//斗地主
swTool.comboObject(lib.mode.doudizhu.connect, {
	connect_doudizhu_mode: {
		item: {
			freeChoiceSkill: '<span class="sw_control">自选技能</span>',
			//"4v4": '<span style="color:red;">四反三忠一主</span>',
			//neimin: '<span style="color:red;">内替换为民（前提是有民）</span>',
			// 'whlw':'<span style="color:red;">文和乱武</span>',
			//'clone': '<span style="color:red;">全选一样</span>',
			//'skill': '<span style="color:red;">随机技能</span>',
			// 'tafang':'<span style="color:skyblue;">塔防</span>',
		},
		name: '<span class="sw_control">游戏模式</span>',
	},
	connect_doudizhu_listNum: {
		name: '<span class="sw_control">玩家选将框</span>',
		frequent: true,
		init: 'normal',
		item: {
			"normal": '正常',
			"10": '十个',
			"20": '二十个',
			"30": '三十个',
			"40": '四十个',
			"50": '五十个',
			"60": '六十个',
			"70": '七十个',
			"80": '八十个',
			"90": '九十个',
			"100": '一百个',
			//'dianjiang': '自由点将'
		},
		restart: true,
		intro: '选将的时候每个人多少个选将框<br>自选技能模式下为每人技能框数量<br>务必计算好将池数量是足够的！<br>自由点将在自选技能模式不生效！'
	},
	connect_doudizhu_freeChoiceSkillNum: {
		name: '<span class="sw_control">技能选择数</span>',
		frequent: true,
		init: '2',
		item: {
			"1": '1',
			"2": '2',
			"3": '3',
			"4": '4',
			"5": '5',
			"6": '6',
			"7": '7',
			"8": '8',
		},
		intro: '选将的时候每个人选多少个技能<br>务必计算好将池数量是足够的！'
	},
	connect_doudizhu_zhuMoreListNum: {
		name: '<span class="sw_control">地主额外技能框数</span>',
		frequent: true,
		init: '10',
		item: {
			"10": '十个',
			"20": '二十个',
			"30": '三十个',
			"40": '四十个',
			"50": '五十个',
		},
		intro: '成为地主的玩家有的额外技能框数'
	},
	connect_doudizhu_zhuMoreSkillNum: {
		name: '<span class="sw_control">地主额外技能数</span>',
		frequent: true,
		init: '1',
		item: {
			"1": '1',
			"2": '2',
			"3": '3',
			"4": '4',
		},
		intro: '成为地主的玩家可以额外选择的技能数'
	},
	
	connect_chooseCharacter_moreTime: {
		name: '<span class="sw_control">选将时间</span>',
		frequent: true,
		item: {
			'10': '10秒',
			'15': '15秒',
			'30': '30秒',
			'60': '60秒',
			'90': '90秒',
			'120': '120秒',
		},
		init: lib.configOL.choose_timeout || '30',
		intro: "选将的时候的时间限制<br>自选技能模式下为选技能的时间限制"
	},
})
lib.mode.doudizhu.connect.update = function (config, map) {
	const switchMode = {
		freeChoiceSkill() {
			const show = [
				'connect_change_card',
				'connect_doudizhu_freeChoiceSkillNum',
				'connect_doudizhu_zhuMoreListNum',
				'connect_doudizhu_zhuMoreSkillNum',

			]
			const hide = [
				'connect_player_number',
				'connect_double_character',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		huanle() {
			const show = [
				'connect_change_card',
				'connect_player_number',
			]
			const hide = [
				'connect_doudizhu_freeChoiceSkillNum',
				'connect_double_character',
				'connect_doudizhu_zhuMoreListNum',
				'connect_doudizhu_zhuMoreSkillNum',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		online() {
			const show = [

			]
			const hide = [
				'connect_doudizhu_freeChoiceSkillNum',
				'connect_change_card',
				'connect_player_number',
				'connect_double_character',
				'connect_doudizhu_zhuMoreListNum',
				'connect_doudizhu_zhuMoreSkillNum',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
		},
		default() {
			const show = [
				'connect_change_card',
				'connect_player_number',
				'connect_double_character',
			]
			const hide = [
				'connect_doudizhu_freeChoiceSkillNum',
				'connect_doudizhu_zhuMoreListNum',
				'connect_doudizhu_zhuMoreSkillNum',
			]
			show.forEach(i => map[i] && map[i].show())
			hide.forEach(i => map[i] && map[i].hide())
			
		}
	}
	switchMode[config.connect_doudizhu_mode in switchMode ? config.connect_doudizhu_mode : 'default']()
}

//合盟鏖战
swTool.comboObject(lib.mode.hemengaozhan?.connect, {
	connect_hemengaozhan_mode: {
		name: '<span class="sw_control">游戏模式</span>',
		frequent: true,
		init: 'normal',
		item: {
			"normal": '标准模式',
			"wuxianhuoli": '无限火力',
		},
		restart: true,
		intro: '模式的选择，无限火力很爽，当然BOSS也会很强'
	},

	connect_player_number: {
		name: '<span class="sw_control">游戏人数</span>',
		init: "8",
		get item() {
			return lib.mode.identity.config.player_number.item;
		},
		frequent: true,
		restart: true,
	},
	connect_hemengaozhan_selects: {
		name: '<span class="sw_control">初始技能池</span>',
		frequent: true,
		init: '25',
		item: {
			"10": '十个',
			"15": '十五个',
			"20": '二十个',
			"25": '二十五个',
			"30": '三十个',
			"35": '三十五个',
			"40": '四十个',
			"45": '四十五个',
			"50": '五十个',
			"55": '五十五个',
			"60": '六十个',
			"65": '六十五个',
			"70": '七十个'
		},
		restart: true,
		intro: '开局选技能的时候每人分多少个技能<br>建议数量25个左右，太多选不过来'
	},
	connect_hemengaozhan_startNum: {
		name: '<span class="sw_control">初始技能上限</span>',
		frequent: true,
		init: '3',
		item: {
			"1": '1',
			"2": '2',
			"3": '3',
			"4": '4',
			"5": '5',
			"6": '6',
			"7": '7',
			"8": '8',
			"9": '9',
			"10": '10',
		},
		restart: true,
		intro: '开局选技能的时候每人技能槽上限多少<br>建议数量3个，不要太多'
	},
	connect_hemengaozhan_more_time: {
		name: '<span class="sw_control">选初始技能时间</span>',
		frequent: true,
		item: {
			'30': '30秒',
			'60': '60秒',
			'90': '90秒',
			'120': '120秒',
			'150': '150秒',
			'180': '180秒',
		},
		init: lib.configOL.choose_timeout || '30'
	},
	connect_hemengaozhan_allSkills: {
		name: '<span class="sw_control">全扩获取技能</span>',
		intro: '开启后无视禁将，所有技能从全扩技能池（所有武将包）中抽取。（除部分被代码禁用的技能外）',
		init: false,
		frequent: true,
	},
	connect_hemengaozhan_tips: {
		name: '<span class=firetext>提示：以下选项本质为作弊选项，开启后会极大减少游戏难度，请谨慎开启</span>',
		clear: true,
		frequent: true,
	},
	connect_hemengaozhan_reviveMode: {
		name: '<span class="sw_control">还魂丹立即复活</span>',
		intro: '玩家死亡后会立即结算复活丹的复活',
		init: false,
		frequent: true,
	},
	connect_hemengaozhan_mofaEnhance: {
		name: '<span class="sw_control">魔法加强</span>',
		intro: '魔法改为每轮限一次且玩家开局就有魔法。魔法的时间限制改为60s，且有文字提示。',
		init: false,
		frequent: true,
	},
	connect_hemengaozhan_tipsEnd: {
		name: '<span class=firetext>——————————</span>',
		clear: true,
		frequent: true,
	},
})

//狼人杀
swTool.comboObject(lib.mode.langrensha?.connect, {
	connect_langrensha_mode: {
		name: '<span class="sw_control">游戏模式</span>',
		frequent: true,
		init: 'normal',
		item: {
			"normal": '标准模式',
			//"wuxianhuoli": '无限火力',
		},
		restart: true,
		intro: '模式的选择'
	},

	connect_player_number: {
		name: '<span class="sw_control">游戏人数</span>',
		init: "8",
		get item() {
			return lib.mode.identity.config.player_number.item;
		},
		frequent: true,
		restart: true,
	},
	connect_langrensha_listNum: {
		name: '<span class="sw_control">玩家选将框</span>',
		frequent: true,
		init: '20',
		item: {
			"10": '十个',
			"20": '二十个',
			"30": '三十个',
			"40": '四十个',
			"50": '五十个',
			"60": '六十个',
			"70": '七十个',
			"80": '八十个',
			"90": '九十个',
			"100": '一百个',
			//'dianjiang': '自由点将'
		},
		restart: true,
		intro: '选将的时候每个人多少个选将框<br>务必计算好将池数量是足够的！'
	},
})
//game.broadcastAll((player) => {
//	player.init("boss_zhugeliang")
//}, game.me)
//lib.mode.hemengaozhan.connect.update = function (config, map) {
//	map.connect_player_number.show();
//}

